package com.example.demo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import javax.swing.*;
import java.util.concurrent.TimeUnit;

@RunWith(SpringRunner.class)
@SpringBootTest
public class OpForString {
    @Autowired
    private RedisTemplate redisTemplate;
    @Test
    public void string(){
        redisTemplate.opsForValue().set("name","lixingzhen");
        redisTemplate.opsForValue().set("age",22);
        Object s=redisTemplate.opsForValue().get("name");
        Object s1=redisTemplate.opsForValue().get("age");
        System.out.println(s);
        System.out.println(s1);
    }

    @Test
    public void string2(){
        redisTemplate.opsForValue().set("name","lixingzhen",3, TimeUnit.SECONDS);
        try{
            Object s=redisTemplate.opsForValue().get("name");
            System.out.println(s);
            Thread.currentThread().sleep(2000);
            Object s1=redisTemplate.opsForValue().get("name");
            System.out.println(s1);
            Thread.currentThread().sleep(5000);
            Object s2=redisTemplate.opsForValue().get("name");
            System.out.println(s2);


        }catch (InterruptedException ie){
            ie.printStackTrace();
        }
    }
    @Test
    public  void string3(){
        redisTemplate.opsForValue().set("name","hello world", 6);
        Object s=redisTemplate.opsForValue().get("name");
        System.out.println(s);
    }
    @Test
    public void string4(){
        redisTemplate.opsForValue().set("name","lxz");
        System.out.println(redisTemplate.opsForValue().getAndSet("name","lixingzhen"));
        System.out.println(redisTemplate.opsForValue().get("name"));
    }
    @Test
    public void string5(){
        redisTemplate.opsForValue().append("q","li");
        System.out.println(redisTemplate.opsForValue().get("q"));
        redisTemplate.opsForValue().append("q","xingzhen");
        System.out.println(redisTemplate.opsForValue().get("q"));
    }

    @Test
    public void string6(){
        redisTemplate.opsForValue().set("key","1www");
        System.out.println(redisTemplate.opsForValue().size("key"));
    }
}
